﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BP.Demo
{
    public class SQLDemo
    {
        public SQLDemo() { }
        public static string DemoSQL(string mark, Hashtable ht = null)
        {
            //学生类的SQL
            if (mark.StartsWith("DemoStudent_Student") == true)
                return Demo_Student(mark, ht);

            //大屏类的sql.
            if (mark.StartsWith("DemoStudent_DataV_StudentHome") == true)
                return DataV_StudentHome(mark, ht);

            throw new Exception("err@没有判断的SQL标记:" + mark);
        }
        public static string Demo_Student(string mark, Hashtable ht = null)
        {
            string key = null;
            if (ht != null && ht.ContainsKey("Key") == true)
                key = ht["Key"].ToString();

            switch (mark)
            {
                case "DemoStudent_Student_BanJi": //班级.
                    return "SELECT No,Name FROM Demo_BanJi ";
                case "DemoStudent_Student_KeMu": //科目.
                    return "SELECT  No,Name FROM Demo_KeMu ";
                case "DemoStudent_Student_BanJiList": //班级列表.
                    return "SELECT No,Name, BZR as \"班主任\", Tel as \"电话\" FROM Demo_BanJi ";
                case "DemoStudent_Student_SearchCity": //城市.
                    return "SELECT No,Name FROM Demo_City WHERE ShengFen='" + key + "' ";
                case "DemoStudent_Student_BanJiFind": //查询班级根据关键字.
                    return "SELECT No,Name FROM Demo_BanJi WHERE No LIKE '%" + key + "%' OR Name LIKE '%" + key + "%'  ";
                case "DemoStudent_Student_FullTeacher": //班级填充DDL.
                    return "SELECT BZR as TeacherName, Tel as TeacherTel FROM Demo_BanJi WHERE No='" + key + "' ";
                case "DemoStudent_Student_FullTBBanJi": //班级填充TB.
                    return "SELECT BZR as TBBZR, Tel as TBTel FROM Demo_BanJi WHERE No='" + key + "' ";
                case "DemoStudent_Student_PopBanJiFull": //班级填充Pop.
                    return "SELECT BZR as PopBZR, Tel as PopTel FROM Demo_BanJi WHERE No='" + key + "' ";
                case "DemoStudent_Student_DtlImpDemo": //DtlImpDemo.vue
                    return "SELECT No AS BianHao,Name AS MingCheng,Addr,Age,Tel,Email AS YouJian From Demo_Student" ;
                default:
                    break;
            }

            throw new Exception("err@没有判断的SQL标记:" + mark);
        }
        public static string DataV_StudentHome(string mark, Hashtable ht = null)
        {
            string key = null;
            if (ht != null && ht.ContainsKey("Key") == true)
                key = ht["Key"].ToString();

            switch (mark)
            {
                case "DemoStudent_DataV_StudentHome_AllStus": //学生总数.
                    return "SELECT count(*) as Num FROM Demo_Student";
                case "DemoStudent_DataV_StudentHome_ZZMM1": //团员数.
                    return "SELECT count(*) as Num FROM Demo_Student WHERE ZZMM=1";
                case "DemoStudent_DataV_StudentHome_XBNum": //求性别数据.
                    return "SELECT Count(*) as Num FROM Demo_Student WHERE XB='" + key + "' GROUP BY XB ";
                case "DemoStudent_DataV_StudentHome_GroupXB": //性别分布.
                    return "SELECT XB, Count(*) as Num FROM Demo_Student GROUP BY XB ";
                case "DemoStudent_DataV_StudentHome_GroupZZMM": //政治面貌.
                    return "SELECT ZZMM, Count(*) as Num FROM Demo_Student GROUP BY ZZMM ";
                default:
                    break;
            }
            throw new Exception("err@没有判断的SQL标记:" + mark);
        }
    }
}
